package com.iot.constants;

import lombok.Getter;
import org.springframework.lang.Nullable;

/**
 * @author RodulphLiu
 * @version 1.0.0
 * @ClassName CallStatusEnum
 * @Date 2017年4月26日 下午5:43:24
 */

public enum CallStatusEnum {
    /**
     * 用于返回数据类型
     */
    SUCCESS(1, "成功"),
    FAIL(2, "失败"),
    IGNORE(3, "请求被忽略,系统不做任何处理"),
    FORBIDDEN(4, "禁止访问"),
    NOT_FOUND(5, "未找到相关权限");

    private final int code;
    @Getter
    private final String desc;

    private CallStatusEnum(int code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static CallStatusEnum valueOf(int statusCode) {
        CallStatusEnum status = resolve(statusCode);
        if (status == null) {
            throw new IllegalArgumentException("No matching constant for [" + statusCode + "]");
        } else {
            return status;
        }
    }

    @Nullable
    public static CallStatusEnum resolve(int statusCode) {
        CallStatusEnum[] var1 = values();
        int var2 = var1.length;

        for (CallStatusEnum status : var1) {
            if (status.code == statusCode) {
                return status;
            }
        }
        return null;
    }

    public int code() {
        return this.code;
    }

    @Override
    public String toString() {
        return this.code + " " + this.name();
    }
}
